using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace Bizspoke.BizTalk.HATPlugIn.BizTalk.Adapter
{
    public class XmlHelper
    {
        public static string Serialize(object obj)
        {
            string xml = "";
            using (StringWriter writer = new StringWriter())
            {
                XmlSerializer serializer = new XmlSerializer(obj.GetType());
                serializer.Serialize(writer, obj);
                xml = writer.ToString();
            }
            return xml;
        }

        public static T Deserialize<T>(string filePath)
        {
            using (FileStream stream = File.OpenRead(filePath))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                return (T)serializer.Deserialize(stream);
            }
        }
    }
}
